<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="../WPromise.js"></script>
<script>
    function fn2() {
        console.log('fn2')
        return WPromise.resolve(WPromise.reject(WPromise.resolve(WPromise.reject('fn2'))))
    }

    function fn3() {
        return new WPromise(((resolve, reject) => {
            setTimeout(() => {
                console.log('fn3')
                resolve('fn3')
            }, 200)
        }))
    }

    var p = WPromise.race([fn2(),fn3()]) // 返回最新执行完成的promise实例
    console.log('实例p', p)

    var p1 = p.then((values) => { // 如果成功执行第一个方法，失败则执行第二个方法
        console.log('成功执行：', values)
        return 'ok'
    }, (reason) => {
        console.log('失败执行：', reason)
        return 'no'
    })
    console.log('新实例p1', p1) // p1实例的状态和值与p中then方法执行是否报错和返回值有关
</script>

</body>
</html>
